<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {
	
	public $editor;
	public $title;
	
	public function __construct(){
		
		parent::__construct();

		$this->load->model('column_model','col');
		$this->load->model('sent_model','article');
		
		$this->editor = $this->col->column_limit();
		$this->title = $this->article->article_right();
	}	

	// 默认加载首页
	public function index()
	{
//		$this->output->enable_profiler(TRUE);  //调试模式
		
		$this->load->model('sent_model','article');
		$data = $this->article->article_check();
		
		//栏目
		$data['editor'] = $this->editor;
		
		//标题
		$data['title'] = $this->title;		
	/*********************************************/
		//echo '这里是查看文章';
		$this->load->model('sent_model','arc');
		$data['article'] = $this->arc->article_find();
//		p($data);die;

/***************/
//		$this->load->model('sent_model','article');
//		$data = $this->article->article_check();
/***************/
		
//		p($data);die;
			
		
//		p($data);die;
		
		$this->load->view('dashboard/index.html',$data);
		
		
	}

	//默认加载分类页
	public function category(){
//		$this->output->enable_profiler(TRUE);  //调试模式
			
		//栏目
		$data['editor'] = $this->editor;

		//标题
		
		$data['title'] = $this->title;
	
		//加载分页栏目
		$cid = $this->uri->segment(2);
		$data['article'] = $this->article->artice_col($cid);
//		p($data);
	
		$this->load->view("dashboard/category.html",$data);
	}

	// 默认加载文章页
	public function details(){
		//栏目
		
		$data['editor'] = $this->editor;

		//标题
		
		$data['title'] = $this->title;
		
		//文章页
		$aid = $this->uri->segment(2);
		$data['art'] = $this->article->article_art($aid);
//		p($data);
		
		$this->load->view("dashboard/details.html",$data);
	}
	
/***************/	
	//搜索框
	public function solo(){
//		echo '这里是搜索功能';
		$input = $this->input->post('ipt');
		$this->load->model('sent_model','sent');
		$data['solo'] = $this->sent->solo($input);
//		$datas = $this->db->select('title')->get('article')->result_array();
		$select = $this->db->where(array('title'=>$input))->get('article')->result_array();
		
		foreach($select as $v):;		
		if($v['title'] == $input){
		//导航页	
		$data['editor'] = $this->editor;
		//标题
		$data['title'] = $this->title;
		
//		p($data);
		$this->load->view('dashboard/solo_result.html',$data);
		}else{
			echo '请输入正确的数值';die;
		}
		endforeach;	
	}
/***************/
	//新用户注册
	public function register(){
		$this->load->view('dashboard/login.html');	
	}
	//注册的动作
	public function register_action(){
		
		$psF = $this->input->post('psF');
		$psS = $this->input->post('psS');
		$username = $this->input->post('username');
				
		if($psF !== $psS || empty($psF)||empty($psS)){
			error('请按格式正确的输入密码','home/register');
		}
		$data = array(
			'username' => $this->input->post('username'),
			'password' => $this->input->post('psF'),
		);
		$this->load->model('Regeist_model','res');
		$data = $this->res->regeist($data,$username);
		success('home/index','注册成功');
	}	
		
}	
	

